package com.niit.service.impl;

import com.niit.entity.Info;
import com.niit.entity.User;
import com.niit.repository.InfoRepository;
import com.niit.repository.UserRepository;
import com.niit.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InfoServiceImpl implements InfoService {
    @Autowired
    private InfoRepository infoRepository;

    @Override
    public Info findByPhoneAndPassword(String phone, String password) {
        return infoRepository.findInfoByPhoneAndPassword(phone, password);
    }

    @Override
    public Info findByPhone(String phone) {
        return infoRepository.findInfoByPhone(phone);
    }

    @Override
    public Info save(Info info) {
        return infoRepository.save(info);
    }

    @Override
    public Info findById(int id) {
        return infoRepository.findById(id).orElse(null);
    }

    @Override
    public Page<Info> findAll(String phone, String username, String realName, String gender, Pageable pageable) {
        Specification<Info> spec = InfoRepository.InfoSpecifications.withDynamicQuery(phone, username, realName, gender);
        return infoRepository.findAll(spec, pageable);
    }

    @Override
    public void deleteById(int id) {
        infoRepository.deleteById(id);
    }


}
